﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RtuReadResponsePackage.cs" company="R.V.Kasner">
//   Copyright © 2011 R.V.Kasner
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Owen.Communication.NewProtocols.ModBus.Rtu
{
    using System.Collections.Generic;

    public abstract class RtuReadResponsePackage : RtuPackageBase
    {
        private readonly List<int> dataBytes;

        protected RtuReadResponsePackage()
        {
            this.dataBytes = new List<int>();
        }

        public int Count
        {
            get
            {
                return this.dataBytes.Count;
            }
        }

        public IList<int> DataBytes
        {
            get
            {
                return this.dataBytes;
            }
        }

        protected override IEnumerable<int> GetData()
        {
            var data = new int[this.dataBytes.Count + 1];
            data[0] = this.Count;

            for (var i = 0; i < this.Count; i++)
            {
                data[i + 1] = this.dataBytes[i];
            }

            return data;
        }
    }
}